package com.beimihu.leetcode;

import java.util.HashMap;
import java.util.Map;

//https://leetcode.cn/problems/isomorphic-strings/?envType=study-plan-v2&envId=top-interview-150
public class IsIsomorphic {
    public boolean isIsomorphic(String s, String t) {
        Map<Character,Character> s2t  = new HashMap<>(),t2s = new HashMap<>();

        for(int i = 0 ;i < s.length() ; i++){
            char a  = s.charAt(i) , b = t.charAt(i);

            if(s2t.containsKey(a) && s2t.get(a) != b || t2s.containsKey(b) && t2s.get(b) != a ){
                return false;
            }
            s2t.put(a,b);
            t2s.put(b,a);
        }
        return true;
    }
}
